//
//  TSRecordSectionHeaderView.swift
//  TSProfitProject
//
//  Created by TMS on 2019/11/7.
//  Copyright © 2019 TMS. All rights reserved.
//

import UIKit

protocol TSRecordSectionHeaderViewDelegate : NSObjectProtocol {
    func didClickFilter()
}

class TSRecordSectionHeaderView: UIView {
    
    weak var delegate: TSRecordSectionHeaderViewDelegate?
    var titleLabel : UILabel!
    
    convenience init(sectionTitle:String) {
        self.init()
        configViews(title: sectionTitle)
    }
    
    func setupSectionTitle(title:String) {
        titleLabel.text = title
    }
    
    @objc func filterAction() {
        
        if self.delegate != nil {
            self.delegate?.didClickFilter()
        }
    }
    
    func configViews(title:String) {
        
        titleLabel = UILabel.init()
        titleLabel.text = title
        titleLabel.textColor = UIColor.hexadecimalColor(hexadecimal: "#282828")
        titleLabel.font = UIFont.systemFont(ofSize: 14, weight: .medium)
        self.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { (make) in
            make.left.equalTo(20)
            make.centerY.equalToSuperview()
        }
        
        let filterBtn = UIButton.init(type: .system)
        filterBtn.setTitle("筛选", for: .normal)
        filterBtn.setTitleColor(UIColor.hexadecimalColor(hexadecimal: "#282828"), for: .normal)
        filterBtn.addTarget(self, action: #selector(filterAction), for: .touchUpInside)
        filterBtn.setEnlargeEdgeNumber(enlarge: 10)
        self.addSubview(filterBtn)
        filterBtn.snp.makeConstraints { (make) in
            make.right.equalToSuperview().inset(20)
            make.centerY.equalToSuperview()
        }
        
        let icon = UIImageView.init(image: UIImage(named: "account_record_filter"))
        self.addSubview(icon)
        icon.snp.makeConstraints { (make) in
            make.centerY.equalTo(filterBtn)
            make.right.equalTo(filterBtn.snp_left).offset(-5)
            make.size.equalTo(CGSize(width: 15, height: 13))
        }
        
    }
    
}
